package com.zx.tradeclient.ctrl.index5;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

import com.zx.base.ctrl.BaseActivity;
import com.zx.base.util.ActivityTaskManager;
import com.zx.base.widget.SlidingPage;
import com.zx.base.widget.SlidingPage.SlidingPagerAdapter;
import com.zx.base.widget.SlidingPage.ViewPagerSelectListener;
import com.zx.tradeclient.R;

public class SandDPageActivity extends BaseActivity implements OnClickListener{
	/** Called when the activity is first created. */

	
	private Button header_left, header_right;
	
	private SlidingPage page;
	private LinearLayout page_layout;
	private SupplyList supplylist;
	private WantList wantlist;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listindex);
		
		if(!(ActivityTaskManager.getInstance().containsName("Index2Activity"))){
			ActivityTaskManager.getInstance().putActivity("Index2Activity", this);
		}

		init();
	}

	@Override
	protected void onResume() {
		if(wantlist!=null)
			wantlist.initview();
		super.onResume();
	}

	private void init() {
		LayoutInflater mInflater = getLayoutInflater();

		
		String[] titles = new String[] {"供应列表","求购列表" };
		page = new SlidingPage(this, 2, R.drawable.page_slider_2);
		page.setTitles(titles);
		setHeader(0);
		page_layout = (LinearLayout) findViewById(R.id.list_main_layout);
		page_layout.addView(page);
		
		final List<View> listViews = new ArrayList<View>();
		listViews.add(mInflater.inflate(R.layout.list, null));
		listViews.add(mInflater.inflate(R.layout.list, null));
		page.getViewPager().setAdapter(new SlidingPagerAdapter(listViews));
		
		page.setViewPageSelectedListener(new ViewPagerSelectListener() {

			@Override
			public void pageSelected(int current) {
				View view = listViews.get(current);
				switch (current) {
				case 0:
					setHeader(0);
					if(supplylist==null)
					supplylist=new SupplyList(SandDPageActivity.this,view);
					break;
				case 1:
					setHeader(2);

					if(wantlist==null)
					wantlist=new WantList(SandDPageActivity.this,view);
					wantlist.init();
					break;
				default:
					break;
				}

			}
		});
		
		page.getViewPager().setCurrentItem(0, false);
		page.getViewPageSelectedListener().pageSelected(0);

	}
	
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == header_left) {
			
		}else if(v == header_right){
			
		}
		
	}


}